package com.android.lovingpet.common.userlist;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.android.lovingpet.base.BasePresenter;
import com.android.lovingpet.common.Back;
import com.android.lovingpet.common.UserModel;
import com.android.lovingpet.bean.Account;

import java.util.ArrayList;

public class UserListPresenter extends BasePresenter<UserListContract.View> implements UserListContract.Presenter {

    private UserListContract.View view;

    public UserListPresenter(UserListContract.View view) {
        this.view = view;
    }

    @Override
    public void getData(ArrayList<Integer> ids) {
        view.showProgress();
        view.clearData();
        if (ids == null || ids.isEmpty()) {
            view.hideProgress();
            return;
        }
        UserModel.getInstance().getInfoList(ids, new Back() {
            @Override
            public void onFailure(String meg) {
                view.hideProgress();
                view.showToast(meg);
            }

            @Override
            public void onSuccess(@Nullable Bundle bundle) {
                view.hideProgress();
                Account account = bundle.getParcelable("account");
                view.addItem(account);
            }
        });
    }
}
